{{- /* cache remote image locally */ -}}
{{- $resource := 0 -}}
{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" ".avif" ".svg" -}}
{{- $suffixValid := (dict "Path" .Path "Suffixes" $suffixList | partial "function/suffix-validation.html") -}}
{{- /* maybe could add domain validation */ -}}
{{- $pass := $suffixValid | or .Pass -}}

{{- if $pass -}}
  {{- with $remoteResource := resources.GetRemote .Path -}}
    {{- with .Err -}}
      {{- erroridf "error-get-remote-image" "%s" . -}}
    {{- else -}}
      {{- if eq $remoteResource.ResourceType "image" -}}
        {{- /* placed remote image in public/images/remote/ */ -}}
        {{- $resource = $remoteResource | resources.Copy (add "/images/remote/" $remoteResource.Name) -}}
      {{- end -}}
    {{- end -}}
  {{- else -}}
    {{- erroridf "error-get-remote-image" "Unable to get remote image %q" .Path -}}
  {{- end -}}
{{- end -}}
{{- return $resource -}}
